<?php

namespace RabbitMq;

require 'RabbitMq.php';

// RabbitMq 各个模式方法操作类
class RabbitMqWork
{
    private $RabbitMq;

    public function __construct($exchageType = '')
    {
        $this->RabbitMq = RabbitMq::instance($exchageType);
    }

    /**
     * 发送（普通）
     * @param $body
     */
    public function send($body)
    {
        $this->RabbitMq->send($body);
    }

    /**
     * 接收（普通）
     * @param $callback
     */
    public function receive($callback)
    {
        $this->RabbitMq->receive($callback);
    }

    /**
     * 发送（工作队列）
     * @param $data
     * @param $queueName
     */
    public function addTask($data, $queueName)
    {
        $this->RabbitMq->addTask($data, $queueName);
    }

    /**
     * 接收（工作队列）
     * @param $callback
     * @param $queueName
     */
    public function workTask($callback, $queueName)
    {
        $this->RabbitMq->workTask($callback, $queueName);
    }

    /**
     * 发布（扇形交换机）
     * @param $data
     */
    public function sendQueue($data)
    {
        $this->RabbitMq->sendQueue($data);
    }

    /**
     * 订阅（扇形交换机）
     * @param $callback
     */
    public function subscribeQueue($callback)
    {
        $this->RabbitMq->subscribeQueue($callback);
    }

    /**
     * 发送（直接交换机）
     * @param $bindingKey
     * @param $data
     */
    public function sendDirect($routingKey, $data)
    {
        $this->RabbitMq->sendDirect($routingKey, $data);
    }

    /**
     * 接收(直接交换机)
     * @param \Closure $callback
     * @param array $bindingKeys
     */
    public function receiveDirect(\Closure $callback, array $bindingKeys)
    {
        $this->RabbitMq->receiveDirect($callback, $bindingKeys);
    }

    /**
     * 发送（主题交换机）
     * @param $routingKey
     * @param $data
     */
    public function sendTopic($routingKey, $data)
    {
        $this->RabbitMq->sendTopic($routingKey, $data);
    }

    /**
     * 接收（主题交换机）
     * @param \Closure $callback
     * @param array $bindingKeys
     */
    public function receiveTopic(\Closure $callback, array $bindingKeys)
    {
        $this->RabbitMq->receiveTopic($callback, $bindingKeys);
    }
}
